from publie.tools import *
from publie.action import *
from publie.testDATE import *

from selenium.webdriver.common.keys import Keys

testCase="DBshop011_管理添加商品"
SP="苹果XR"
rich=7999

firefox=openB(adminurl)
adminlogin(firefox)
menu2(firefox,"商品管理","管理商品")
s=firefox.find_element_by_xpath("//body").text
time.sleep(4)
l="商品数\："
r="\)"
time.sleep(2)
ID1=reGetString(s,l,r)
print(ID1)

# "1.点击添加商品按钮，商品名称填写“苹果XR”,本店价格“7999”，商品类型“虚拟商品”。
firefox.find_element_by_partial_link_text("添加商品").click()
firefox.find_element_by_id("goods_name").send_keys(SP)
firefox.find_element_by_id("goods_shop_price").send_keys(rich)
s=Select(firefox.find_element_by_id("goods_type"))
s.select_by_visible_text("虚拟商品")
# 2.点击“保存商品”按钮，后台保存成功添加的商品。"
firefox.find_element_by_xpath("//div[@id='sticky_navigation_right']/button").click()
#断言
s=firefox.find_element_by_xpath("//body").text
time.sleep(4)
l="商品数\："
r="\)"
time.sleep(2)
ID2=reGetString(s,l,r)
print(ID2)

if int(ID1)+1 == int(ID2):
    writeLog("%s 测试通过" % testCase)
else:
    writeLog("%s 测试失败" % testCase)
    getPhoto(firefox)
firefox.quit()